<?php

namespace App\Http\Controllers\Backend;
use App\Http\Controllers\BaseController;
use App\Http\Middleware\AdminAuth;
use App\Services\User\UserService;
use Illuminate\Http\Request;
/**
 * 系统管理控制器
 *
 * @package App\Http\Controllers\H5
 * @author WangBin
 * @date 2021-06/11
 */
class SysController extends BaseController
{
    public function __construct()
    {
        $this->middleware(AdminAuth::class);
    }

    /**
     * 用户登录获取token
     *
     * @param Request $request
     * @return
     */
    public function login(Request $request)
    {
        return $this->success(['token' => '111111111111111111', 'user' => []]);
    }

    /**
     * 获取用户信息
     *
     * @param Request $request
     * @return
     */
    public function get(Request $request)
    {
        return $this->success(['user_id' => 1, 'name' => 'admin', 'token' => '111111111111111111', 'perms' => ['*'], 'avatar' => 'https://juhuixing-public.oss-cn-shenzhen.aliyuncs.com/luq950dq4wzhsn54eq1y.jpeg']);
    }

    /**
     * 保存用户
     *
     * @param Request $request
     * @throws \App\Exceptions\BusinessException
     */
    public function update(Request $request)
    {
        $userId = $request->input('user_id');
        $username = $request->input('username');
        $password = $request->input('password');
        $name = $request->input('name');
        $email = $request->input('email');
        $phone = $request->input('phone');
        $avator = $request->input('avator');
        $groupId = $request->input('group_id');
        $roleId = $request->input('role_id');

        $data = [
            'user_id' => $userId,
            'username' => $username,
            'name' => $name,
            'password' => $password,
            'email' => $email,
            'phone' => $phone,
            'avator' => $avator,
            'group_id' => $groupId,
            'role_id' => $roleId
        ];
        $ret = UserService::getInstance()->update($data);
        $this->success(['user_id' => $ret]);
    }
}